package com.yunxin.core.infra.common.order.utils;

import com.yunxin.core.domain.external.product.ProductAllocationDetail;
import com.yunxin.core.domain.model.order.OrderUserApplyDetail;
import com.yunxin.core.utils.infra.utils.AttributeDetermineUtils;

/**
 * @author zero°
 * @since 2023-07-04
 */
public enum AllocationAttributeDetermineUtils {

    /**
     * 实例
     */
    X;

    /**
     * 匹配结果
     *
     * @param detailDTO 产品详情
     * @param applyDetail 申请详情
     * @param age 年龄
     * @param sex 性别
     * @return 匹配结果
     */
    public boolean isMatchResult(ProductAllocationDetail detailDTO, OrderUserApplyDetail applyDetail, Integer age, Integer sex) {
        //年龄按段
        boolean ageResult = AllocationAttributeDetermineUtils.X.isAgeResult(detailDTO, age);
        //教育程度判断
        boolean educationResult = AllocationAttributeDetermineUtils.X.isResult(applyDetail.getEducationLevel(), detailDTO.getEducationLevels());
        //社保判断
        boolean socialSecurityResult = AllocationAttributeDetermineUtils.X.isSocialSecurityResult(applyDetail.getSocialSecurityLevel(), detailDTO.getSocialSecurityLevels());
        //公积金判断
        boolean accumulationFundResult = AllocationAttributeDetermineUtils.X.isAccumulationFundResult(applyDetail.getAccumulationFundLevel(), detailDTO.getAccumulationFundLevels());
        //芝麻分判断
        boolean sesameSeedResult = AllocationAttributeDetermineUtils.X.isResult(applyDetail.getSesameSeedQuota(), detailDTO.getSesameSeedQuotas());
        //信用卡判断
        boolean creditCardResult = AllocationAttributeDetermineUtils.X.isCreditCardResult(applyDetail.getCreditCard(), detailDTO.getCreditCards());
        //房产判断
        boolean houseResult = AllocationAttributeDetermineUtils.X.isHouseResult(applyDetail.getHouseLevel(), detailDTO.getHouseLevels());
        //车产判断
        boolean vehicleResult = AllocationAttributeDetermineUtils.X.isVehicleResult(applyDetail.getVehicleLevel(), detailDTO.getVehicleLevels());
        //保险判断
        boolean insureResult = AllocationAttributeDetermineUtils.X.isInsureResult(applyDetail.getInsure(), detailDTO.getInsures());
        //职业判断
        boolean occupationResult = AllocationAttributeDetermineUtils.X.isResult(applyDetail.getOccupation(), detailDTO.getOccupations());
        //职业收入判断
        boolean occupationIncomeResult = AllocationAttributeDetermineUtils.X.isResult(applyDetail.getOccupationMonthlyIncome(), detailDTO.getOccupationIncomes());
        //京东白条额度判断
        boolean jdBtResult = AllocationAttributeDetermineUtils.X.isQuotaResult(applyDetail.getJdBtQuota(), detailDTO.getJdBtQuotas());
        // 蚂蚁花呗判断
        boolean antCreditPayResult = AllocationAttributeDetermineUtils.X.isQuotaResult(applyDetail.getAntCreditPayQuota(), detailDTO.getAntCreditPayQuotas());
        //微粒贷判断
        boolean microLoanResult = AllocationAttributeDetermineUtils.X.isQuotaResult(applyDetail.getMicroLoanQuota(), detailDTO.getMicroLoanQuotas());
        //性别判断
        boolean sexResult = AllocationAttributeDetermineUtils.X.isResult(sex, detailDTO.getSexes());
        //逾期判断
        boolean beOverdueResult = AllocationAttributeDetermineUtils.X.isBeOverdueResult(applyDetail.getBeOverdue(), detailDTO.getBeOverdue());
        //城市判断
        boolean cityResult = AllocationAttributeDetermineUtils.X.isCityResult(applyDetail.getWorkCity(), detailDTO.getCityConfig());
        //最终结果判断
        return ageResult && educationResult && socialSecurityResult && accumulationFundResult && sesameSeedResult
                && creditCardResult && houseResult && vehicleResult && insureResult && occupationResult && occupationIncomeResult
                && jdBtResult && antCreditPayResult && microLoanResult && sexResult && beOverdueResult && cityResult;
    }

    /**
     * 年龄判断
     *
     * @param detailDTO detailDTO
     * @param age       age
     * @return boolean
     */
    private boolean isAgeResult(ProductAllocationDetail detailDTO, Integer age) {
        return AttributeDetermineUtils.X.isAgeResult(detailDTO.getCustomMinAge(), detailDTO.getCustomMaxAge(), age);
    }

    /**
     * 属性判断(= 教育程度、芝麻分、职业、职业收入、性别、逾期)
     *
     * @param userAttribute     userAttribute
     * @param productAttributes productAttributes
     * @return boolean
     */
    private boolean isResult(Integer userAttribute, String productAttributes) {
        return AttributeDetermineUtils.X.isResult(userAttribute, productAttributes);
    }

    /**
     * 额度属性判断(= 京东白条、蚂蚁花呗、微粒贷)
     *
     * @param userQuotaAttribute     userQuotaAttribute
     * @param productQuotaAttributes productAttributes
     * @return boolean
     */
    private boolean isQuotaResult(Integer userQuotaAttribute, String productQuotaAttributes) {
        return AttributeDetermineUtils.X.isQuotaResult(userQuotaAttribute, productQuotaAttributes);
    }

    /**
     * 社保判断
     *
     * @param userSocialSecurity    userSocialSecurity
     * @param productSocialSecurity productSocialSecurity
     * @return boolean
     */
    private boolean isSocialSecurityResult(Integer userSocialSecurity, String productSocialSecurity) {
        return AttributeDetermineUtils.X.isSocialSecurityResult(userSocialSecurity, productSocialSecurity);
    }

    /**
     * 公积金判断
     *
     * @param userAccumulationFund     userAccumulationFund
     * @param productAccumulationFunds productAccumulationFunds
     * @return boolean
     */
    private boolean isAccumulationFundResult(Integer userAccumulationFund, String productAccumulationFunds) {
        return AttributeDetermineUtils.X.isAccumulationFundResult(userAccumulationFund, productAccumulationFunds);
    }


    /**
     * 信用卡判断
     *
     * @param userCreditCard     userCreditCard
     * @param productCreditCards productCreditCards
     * @return boolean
     */
    private boolean isCreditCardResult(Integer userCreditCard, String productCreditCards) {
        return AttributeDetermineUtils.X.isCreditCardResult(userCreditCard, productCreditCards);
    }


    /**
     * 房产判断
     *
     * @param userHouse     userHouse
     * @param productHouses productHouses
     * @return boolean
     */
    private boolean isHouseResult(Integer userHouse, String productHouses) {
        return AttributeDetermineUtils.X.isCreditCardResult(userHouse, productHouses);
    }

    /**
     * 车产判断
     *
     * @param userVehicle     userVehicle
     * @param productVehicles productVehicles
     * @return boolean
     */
    private boolean isVehicleResult(Integer userVehicle, String productVehicles) {
        return AttributeDetermineUtils.X.isVehicleResult(userVehicle, productVehicles);
    }

    /**
     * 保险判断
     *
     * @param userInsure     userInsure
     * @param productInsures productInsures
     * @return boolean
     */
    private boolean isInsureResult(Integer userInsure, String productInsures) {
        return AttributeDetermineUtils.X.isInsureResult(userInsure, productInsures);
    }

    /**
     * 逾期判断
     *
     * @param userBeOverdue    userBeOverdue
     * @param productBeOverdue productBeOverdue
     * @return boolean
     */
    private boolean isBeOverdueResult(Integer userBeOverdue, String productBeOverdue) {
        return AttributeDetermineUtils.X.isBeOverdueResult(userBeOverdue, productBeOverdue);
    }

    /**
     * 城市判断
     *
     * @param userCity          userCity
     * @param productCityConfig productCityConfig
     * @return boolean
     */
    private boolean isCityResult(String userCity, String productCityConfig) {
        return AttributeDetermineUtils.X.isCityResult(userCity, productCityConfig);
    }
}
